import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_pink_app/serialized/recommend.dart';
import '../components/entrance_page.dart';
import '../components/regist_page.dart';
import '../components/main_page.dart';
import '../components/video_page.dart';

// 页面状态类
class BiliPageStatus {
  BiliPageStatus(this.path, {this.videoInfo, this.tokenIsExpired});

  String path; // 路径
  VideoInfo videoInfo; // 视频信息
  bool tokenIsExpired; // token凭证是否过期
}

// 生成动态页面哈希表
Map<String, Widget> generatePageMap(BiliPageStatus status) {
  return {
    '/': BiliEntrancePage(tokenIsExpired: status.tokenIsExpired),
    '/regist': BiliRegistPage(),
    '/main': BiliMainPage(),
    '/video': BiliVideoPage(status?.videoInfo),
  };
}

// 构建材料设计页面
MaterialPage buildMaterialPage(BiliPageStatus status) {
  final pageMap = generatePageMap(status);
  final page = pageMap[status.path];
  assert(page is Widget, '哈希表对应字段实例化的对象不是Widget类型');
  return MaterialPage(
      key: ObjectKey(status.path), child: page, name: status.path);
}

// 构造IOS设计页面
CupertinoPage buildCupertinoPage(BiliPageStatus status) {
  final pageMap = generatePageMap(status);
  final page = pageMap[status.path];
  assert(page is Widget, '哈希表对应字段实例化的对象不是Widget类型');
  return CupertinoPage(key: ObjectKey(status), child: page, name: status.path);
}
